import express from "express";
import { fileURLToPath } from 'url';
import { dirname } from 'path';
import path from "node:path";

const app = express();

app.use(express.json());

// 获取当前文件所在目录
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

// 设置静态资源目录为public
app.use(express.static(path.join(__dirname, 'public')));

let port = 3000;

// 当访问根路径时进行重定向
app.get('/', (req, res) => {
    // 重定向到index.html页面
    res.redirect('/html/index.html');
});


app.listen(port, () => {
    console.log(`Server is running at http://127.0.0.1:${port}/`);
});